#include<bits/stdc++.h>
using namespace std;
int n;
int T;
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    while(T--){
        cin>>n;
        int a[n],c[n],ton[n];
        memset(ton,sizeof(ton),0);
        bool color[n];
        for(int i=1;i<=n;i++){
            cin>>a[i];
            ton[a[i]]++;
            c[i]=0;
        }
        bool flag=0;
        for(int i=1;i<=1000005;i++){
            if(ton[i]>1){
                flag=1;
                break;
            }
        }
        if(flag==0){
            cout<<0<<endl;
        }
        else{
            for(int i=1;i<=n-1;i++){
                for(int j=i+1;j<=n;j++){
                    if(a[i]==a[j]){
                        if(i==1||color[i-1]==0){
                            color[i]=1;
                            color[j]=1;
                        }
                        else{
                            color[i]=0;
                            color[j]=0;
                        }
                    }
                }
            }
            int sum=0;
            for(int i=1;i<=n;i++){
                for(int j=i-1;j>=0;j--){
                    if(color[i]==color[j]&&a[i]==a[j]){
                        c[i]=a[i];
                        break;
                    }
                    if(color[i]==color[j]&&a[i]!=a[j]){
                        c[i]=0;
                    }
                }
                sum+=c[i];
            }
            cout<<sum<<endl;
        }
    }
return 0;
}
